// pages/create_task/create_task.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height:'',
    title:'',
    disc:'',
    gold:'',
    s_date:'2022-04-11',
    e_date:'2022-04-12',
    s_time:'12:00',
    e_time:'13:00'
  },
  sDateChange:function(e){
    this.setData({
      s_date: e.detail.value
    })
  },
  eDateChange:function(e){
    this.setData({
      e_date: e.detail.value
    })
  },
  sTimeChange(e) {
    this.setData({
      s_time: e.detail.value
    })
  },
  eTimeChange(e) {
    this.setData({
      e_time: e.detail.value
    })
  },
  formSubmit:function(e){
    var formdata = e.detail.value 
    var s_time = this.data.s_date +" "+ this.data.s_time
    var e_time = this.data.e_date +" "+ this.data.e_time
    let task_name = formdata.title
    let task_msg = formdata.disc
    let task_gold = formdata.gold
    let user_id = wx.getStorageSync('user').user_id
    let that = this
    wx.request({
      url: 'http://121.37.209.61:8888/task/add',
      method:'post',
      data:{
        task_name: task_name,
        task_gold: task_gold,
        task_s_time: s_time,
        task_e_time: e_time,
        task_creator_id: user_id,
        task_msg: task_msg
      },
      success(res){
        if(res.data.code == 200){
          //表单置空
          that.setData({
            task_name:'',
            task_msg:'',
            task_gold:''
          })
          wx.showToast({
            title: '任务发布成功',
            icon: 'success',
            duration: 1500
          })
        }else{
          wx.showToast({
            title: '任务发布失败',
            icon: 'error',
            duration: 1500
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    // 监听窗口高度
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage () {

  }
})